//
//  DetailStoryCell.m
//  MyItem
//
//  Created by SoulWater on 16/1/7.
//  Copyright © 2016年 admin. All rights reserved.
//

#import "DetailStoryCell.h"
#import "wareInfoModel.h"
@implementation DetailStoryCell

- (void)awakeFromNib {
    // Initialization code
}

-(void)setWareModel:(wareInfoModel *)wareModel
{
    if (_wareModel != wareModel) {
        
        _wareModel = wareModel;
        
        [self setNeedsLayout];
    }
}


-(void)layoutSubviews
{
    [super layoutSubviews];

    if (self.wareModel.imgText != nil) {
        
        UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 0, HScreenWidth-20, 0)];

        label.numberOfLines =0;
        label.text = self.wareModel.imgText;
        [self.contentView addSubview:label];
        //计算label高度
        NSDictionary *attribut = @{NSFontAttributeName:[UIFont systemFontOfSize:20]};
        CGRect rect = [self.wareModel.imgText boundingRectWithSize:CGSizeMake(HScreenWidth, 1000) options:NSStringDrawingUsesLineFragmentOrigin attributes:attribut context:NULL];
        CGFloat labelHeight = rect.size.height + 5;
        label.height = labelHeight;
    
        
        UIImageView *imgView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, HScreenWidth, HScreenWidth/3*2)];
        NSString *imgURL = self.wareModel.imgURL;
        NSString *newURL = [imgURL substringToIndex:imgURL.length-5];
        [imgView sd_setImageWithURL:[NSURL URLWithString:newURL]];
        [self.contentView addSubview:imgView];
        imgView.top = label.bottom;
    }
    else{
        UIImageView *imgView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, HScreenWidth, HScreenWidth/3*2)];
        NSString *imgURL = self.wareModel.imgURL;
        NSString *newURL = [imgURL substringToIndex:imgURL.length-5];
        [imgView sd_setImageWithURL:[NSURL URLWithString:newURL]];

        [self.contentView addSubview:imgView];

    }
    
}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
